package org.cogaen.java2d.xml;

import java.awt.Color;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.cogaen.core.Core;
import org.cogaen.logging.LoggingService;
import org.cogaen.resource.ResourceManager;

public class ColorXmlHandle extends XmlHandle {

	private static final String LOGGING_SOURCE = ResourceManager.LOGGING_SOURCE;
	private ColorParser colorParser;
	
	public ColorXmlHandle(String resourceName, String filename) {
		super(resourceName, filename, ColorParser.createFilter(resourceName));
		this.colorParser = new ColorParser();
	}

	@Override
	protected Object parseXml(Core core, XMLStreamReader reader) throws XMLStreamException {
		try {
			this.colorParser.parse(reader);
			return this.colorParser.getColor();
		} catch (ParseException e) {
			LoggingService logger = LoggingService.getInstance(core);
			logger.logWarning(LOGGING_SOURCE, "unable to load color '" + getName() + "': " + e.getMessage());
			return Color.CYAN;
		}				
	}

}
